package com.waimai.mobile.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.waimai.mobile.R;

/**
 * Created by lin on 2015/6/13.
 */
public class BaseActivity01 extends ActionBarActivity{

    private ActionBar actionBar;
    private int currentPage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        actionBar = getSupportActionBar();
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setTitle("外卖");

        currentPage = 0;
    }


    public void setActionBarTitle(String title){
        actionBar.setTitle(title);
    }

    public void setCurrentPage(int currentPage){
        this.currentPage = currentPage;
        supportInvalidateOptionsMenu();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()){
            case android.R.id.home:
                Intent intent = new Intent(getApplicationContext(), LocationActivity.class);
                startActivity(intent);
                break;
        }
        return true;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        switch (currentPage){
            case 0:
                actionBar.setDisplayShowHomeEnabled(true);
                actionBar.setDisplayHomeAsUpEnabled(true);
                actionBar.setHomeAsUpIndicator(R.mipmap.ic_location);
                actionBar.setTitle("位置");
                break;
            case 1:
                actionBar.setDisplayHomeAsUpEnabled(false);
                actionBar.setTitle("订单");
                break;
            case 2:
                actionBar.setDisplayHomeAsUpEnabled(false);
                actionBar.setTitle("我的");
                break;
        }
        return true;
    }
}
